

import JsonManager from "../manager/json_manager";
import StorageManager from "../manager/storage_manager";
import Enemy from "./Enemy";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ExplodeObj extends cc.Component {

    @property(cc.Label)
    label: cc.Label = null;
    baseATk: number = 3
    atk: number = 3;

    onLoad() {
        const particleSystem = this.node.getComponent(cc.ParticleSystem);
        let size = StorageManager.instance.explosionRadius;
        let extra = JsonManager.instance.getDataByName('skill_extra')[3]
   
        
        size += extra.range * StorageManager.instance.skillLevel[3]
        if (particleSystem) {
            particleSystem.startSize = particleSystem.startSize * size;
            particleSystem.endSize = particleSystem.endSize * size;
            particleSystem.speed = particleSystem.speed * size;
        }
        this.atk = this.baseATk + extra.atk * StorageManager.instance.skillLevel[3]
        cc.log('---------------------------atk--------:' + this.atk)

        this.node.setScale(size, size)

        this.scheduleOnce(() => {
            this.node.destroy();
        }, 1.5);
    }

    start() {

    }

    onCollisionEnter(other, self) {
        if (other.getComponent(Enemy)) {
            // MainManager.instance.removeEnemyById(other.getComponent(Enemy).globalId)
            other.getComponent(Enemy).takeDamage(this.atk);
        }

    }
}
